Basic Linux Commands

Welcome to the ultimate guide of essential Linux commands! Each command here is explained in about 50 words, including syntax and usage, to help beginners and enthusiasts navigate Linux systems confidently.

1. sudo

Allows users to run programs with the security privileges of another user (by default, the superuser). It's commonly used for administrative tasks such as installing software. Usage example: sudo apt install package_name. It requires authentication and logs every command run through it for security auditing.

2. pwd

Prints the full pathname of the current working directory. It's helpful to confirm where you are within the Linux file system hierarchy. Simply type pwd to get an absolute path from the root (/). No options are necessary for basic use.

3. cd

Changes the current directory to another. You can move using relative paths (e.g., cd ../) or absolute paths (e.g., cd /home/user). Typing cd without arguments takes you to your home directory. Essential for navigating the file system.

4. ls

Lists directory contents. You can add options like -l (long format), -a (include hidden files), and -h (human-readable file sizes). Usage: ls -lah. It provides quick insight into file structure and permissions.

5. cat

Concatenates and displays file content. It’s often used to view text files quickly. Example: cat filename.txt. You can also use it to combine multiple files or redirect output using > and >> operators.

6. cp

Copies files or directories. Use cp file.txt /destination/ to copy files and cp -r folder /destination/ for directories. It's useful for backing up data or moving data between locations.

7. mv

Moves or renames files and directories. Syntax: mv oldname newname. It’s useful for organizing files and renaming without duplication. For moving between directories, include a path: mv file.txt /path/to/destination.

8. mkdir

Creates new directories. Add -p to create nested directories in a single command. Example: mkdir -p /new/folder/path. Ensure you have appropriate permissions in the target location.

9. rmdir

Removes empty directories. It won’t work if the directory contains files. Use rmdir directory or rmdir -p parent/child to remove nested directories.

10. rm

Deletes files and directories. Add -r for directories and -f to force deletion without prompt. Example: rm -rf folder. Be cautious—this action is irreversible unless backups exist.

11. touch

Creates a new empty file or updates the timestamp of an existing file. Commonly used in scripting to create files quickly. Example: touch newfile.txt. You can also create multiple files at once using space-separated names.

12. locate

Searches for files by name using a prebuilt index. Much faster than find, but may not reflect real-time changes unless updated with updatedb. Example: locate file.txt.

13. find

Recursively searches directories for files matching given criteria such as name, type, or size. Example: find /home -name file.txt. Powerful for deep searches.

14. grep

Searches for text patterns in files. Useful for logs and large text files. Example: grep 'error' logfile.log. Supports regular expressions and recursive search with -r.

15. df

Shows disk usage of mounted filesystems. Add -h for human-readable format. Example: df -h. Useful to check if a partition is full.

16. du

Displays size of directories and files. Use du -sh folder/ to get a summary of folder size. Helpful for tracking down disk space usage.

17. head

Displays the first few lines of a file. Default is 10 lines. Use -n to specify line count. Example: head -n 5 file.txt.

18. tail

Displays the last lines of a file. Use tail -f to follow updates live, great for monitoring logs. Example: tail -f /var/log/syslog.

19. diff

Compares two files line by line. Useful in development to detect changes. Example: diff old.txt new.txt. Use -u for unified format.

20. tar

Archives files into a .tar file. Add -z for gzip compression. Example: tar -czvf archive.tar.gz folder/. Also used to extract archives.

21. chmod

Changes file permissions. Use numbers (e.g., 755) or symbols (e.g., u+x). Example: chmod 755 script.sh. Essential for setting execute permissions.

22. chown

Changes the owner and group of a file. Example: chown user:group file.txt. Requires sudo. Useful when managing shared environments.

23. jobs

Displays background jobs started from the current terminal. You can bring jobs to foreground using fg. Useful in multitasking with terminal processes.

24. kill

Sends a signal to a process, usually to stop it. Use kill PID or kill -9 PID to forcefully terminate. Check PID using ps.

25. ping

Tests connectivity to another host. It sends ICMP echo requests and shows the response time. Example: ping google.com.

26. wget

Downloads files from the web via terminal. Works with HTTP, HTTPS, and FTP. Example: wget https://example.com/file.zip. Can resume downloads with -c.

27. uname

Shows system information like kernel name, OS, and architecture. Example: uname -a. Useful for checking system specs.

28. top

Displays live system resource usage and running processes. Press q to quit. Provides CPU, memory, and process monitoring.

29. history

Shows the list of previously executed commands in the shell. Useful for recalling or reusing commands. Clear history with history -c.

30. man

Displays the manual page for commands. Example: man ls. Learn options and syntax for any Linux command.

31. echo

Prints strings to the terminal. Often used in scripts for output. Example: echo "Hello World".

32. zip/unzip

Compresses (zip) and extracts (unzip) zip files. Example: zip archive.zip file.txt and unzip archive.zip.

33. hostname

Displays or sets the system hostname. Example: hostname. Useful in networking configurations and system identification.

34. useradd/userdel

Adds or deletes user accounts. Use useradd username and userdel username. Requires root privileges.

35. apt-get

Package management command for Debian-based systems. Example: sudo apt-get install packagename. Use update and upgrade to manage system packages.

36. nano/vi/jed

Text editors used in the terminal. nano is user-friendly, vi is powerful but complex. Use nano file.txt to start editing quickly.

37. alias/unalias

Create shortcuts for commands using alias. Remove them with unalias. Example: alias ll='ls -la'.

38. su

Switches to another user account. Use su - username for login shell. Default is root if no username is provided.

39. htop

An interactive process viewer, similar to top but with color and easier navigation. Use arrow keys and function keys for controls.

40. ps

Displays a snapshot of active processes. Use ps aux to see all system processes with detailed information.

Thank you! Share this page with your friends who are interested in Linux!